package com.konne.nightmare.FastPublicOpinion.ui.dialog;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.konne.nightmare.FastPublicOpinion.R;

/**
 * Create by ws.
 * on Data:2022/2/12  Time:下午 2:55.
 * description: 选择输入类型的popup .
 */
public class ImportTypePopup {
    public static void show(Activity activity,View v,ImportTypeListener typeListener) {
        ViewGroup view = (ViewGroup) LayoutInflater.from(v.getContext()).inflate(R.layout.pupup_import_type, null);
        PopupWindow popWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,true);
        popWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popWindow.showAsDropDown(v, -SizeUtils.dp2px(80), 0);
        WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
        lp.alpha = 0.7f;
        activity.getWindow().setAttributes(lp);
        popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
                lp.alpha = 1f;
                activity.getWindow().setAttributes(lp);
            }
        });
        View.OnClickListener onClickListener=new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popWindow.dismiss();
                if(typeListener!=null){
                    typeListener.importType((Integer) view.getTag());
                }
            }
        };
        for (int i = 0; i < view.getChildCount(); i++) {
            view.getChildAt(i).setTag(i);
            view.getChildAt(i).setOnClickListener(onClickListener);
        }
    }
    public interface ImportTypeListener{
        void importType(int type);
    }
}
